//
//  DCBeautyHotTopicCell.m
//  CDDStoreDemo
//
//  Created by 陈甸甸 on 2017/12/7.
//  Copyright © 2017年 RocketsChen. All rights reserved.
//

#import "DCBeautyHotTopicCell.h"

#import "DCBeautyHotItem.h"

#import "DCGroupImageCell.h"

@interface DCBeautyHotTopicCell()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

/* collectionView */
@property (strong , nonatomic)UICollectionView *collectionView;
//@property (strong, nonatomic)  UILabel *hotTitleLabel;
//@property (strong, nonatomic)  UILabel *subTitleLabel;
//@property (strong, nonatomic)  UIButton *watchNumLabel;
///** 图片*/
//@property (nonatomic,strong) UIImageView *logoImage;
///** miao*/
//@property (nonatomic,strong) UILabel *logolabel;
/* 图片模型 */
@property (strong , nonatomic)NSMutableArray *picArray;

@end

static NSString *const DCGroupImageCellID = @"DCGroupImageCell";

@implementation DCBeautyHotTopicCell

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self setUpAllChildView];
    }
    return self;
}

- (void)setUpAllChildView{
    WEAKSELF
    self.hotTitleLabel = [[UILabel alloc]init];
    self.hotTitleLabel.font = TITLE_FONT(30);
    self.hotTitleLabel.numberOfLines = 0;
    [self addSubview:self.hotTitleLabel];
    [self.hotTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(10);
        make.left.mas_equalTo(self).with.offset(10);
        make.right.mas_equalTo(self).with.offset(-10);
        make.height.mas_equalTo(10);
    }];
    
    self.subTitleLabel = [[UILabel alloc]init];
    self.subTitleLabel.font = TITLE_FONT(26);
    self.subTitleLabel.numberOfLines = 0;
    [self addSubview:self.subTitleLabel];
    [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.hotTitleLabel);
        make.right.mas_equalTo(weakSelf.hotTitleLabel);
        make.top.mas_equalTo(weakSelf.hotTitleLabel.mas_bottom).with.offset(10);
        make.height.mas_equalTo(10);
    }];
    
    self.logoImage = [[UIImageView alloc]init];
    [self.logoImage setImage:IMAGE(@"guome")];
    [self addSubview:self.logoImage];
    [self.logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self).with.offset(-5);
        make.left.mas_equalTo(self).with.offset(10);
        make.size.mas_equalTo(weakSelf.logoImage.image.size);
    }];
    
    self.logolabel = [[UILabel alloc]init];
    self.logolabel.font = TITLE_FONT(30);
    self.logolabel.text = @"最全攻略";
    self.logolabel.textColor = [UIColor lightGrayColor];
    [self addSubview:self.logolabel];
    [self.logolabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.logoImage);
        make.left.mas_equalTo(weakSelf.logoImage.mas_right).with.offset(10);
        make.width.mas_equalTo(SCREEN_WIDTH/4);
    }];
    
    self.watchNumLabel = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.watchNumLabel setImage:IMAGE(@"mShop_broswer_icon") forState:UIControlStateNormal];
    [self.watchNumLabel addTarget:self action:@selector(watchNumLabelClick:) forControlEvents:UIControlEventTouchUpInside];
    self.watchNumLabel.titleLabel.font = TITLE_FONT(28);
    [self.watchNumLabel setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [self addSubview:self.watchNumLabel];
    [self.watchNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.logoImage);
        make.right.mas_equalTo(self).with.offset(-10);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(35);
    }];

    
    UICollectionViewFlowLayout *dcFlowLayout = [UICollectionViewFlowLayout new];
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:dcFlowLayout];
    dcFlowLayout.minimumLineSpacing = dcFlowLayout.minimumInteritemSpacing = 0;
    dcFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_collectionView];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    
    [_collectionView registerClass:[DCGroupImageCell class] forCellWithReuseIdentifier:DCGroupImageCellID];
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.hotTitleLabel.mas_bottom).with.offset(10);
        [make.left.mas_equalTo(self)setOffset:5];
        [make.right.mas_equalTo(self)setOffset:-5];
        [make.bottom.mas_equalTo(weakSelf.watchNumLabel.mas_top)setOffset:-DCMargin];
    }];
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self);
        make.left.mas_equalTo(self).with.offset(10);
        make.right.mas_equalTo(self).with.offset(-10);
        make.height.mas_equalTo(0.4);
    }];
}

- (NSMutableArray *)picArray{
    if (!_picArray) {
        _picArray = [NSMutableArray array];
    }
    return _picArray;
}


- (void)setHotItem:(DCBeautyHotItem *)hotItem{
    _hotItem = hotItem;
    self.hotTitleLabel.text = hotItem.beautyTitle;
    self.subTitleLabel.text = hotItem.secondTitle;
    [self.watchNumLabel setTitle:[NSString stringWithFormat:@"%@ 万",hotItem.watchNum] forState:0];
    
    _picArray = [NSMutableArray arrayWithArray:hotItem.groupImage];
}

#pragma mark - <UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _picArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DCGroupImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:DCGroupImageCellID forIndexPath:indexPath];
    NSString *groupIamgeUrl = _picArray[indexPath.row];
    cell.groupImageUrl = groupIamgeUrl;
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(_collectionView.dc_height, _collectionView.dc_height);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"点击来的第%ld行第%ld个热门商品",indexPath.section,indexPath.row);
}

- (void)watchNumLabelClick:(UIButton *)btn{
    NSLog(@"查看的人数");
}

@end
